
<template>
  <div>
    <h1></h1><hr>
    <div class="radio">
      排序：
      <el-radio-group v-model="reverse">
        <el-radio :label="true">倒序</el-radio>
        <el-radio :label="false">正序</el-radio>
      </el-radio-group>
    </div>

    <el-timeline :reverse="reverse">
      <el-timeline-item
          v-for="(activity, index) in activities"
          :key="index"
          :timestamp="activity.timestamp"><br>
        {{activity.growthCondition}}<br>
        {{activity.createTime}}
      </el-timeline-item>
    </el-timeline>

    <div>
      <template>
        <!-- 二维码 -->
        <div class="code">
          <img :src="img" />
        </div>
      </template>
    </div>
  </div>
</template>

<script>
import AraleQRCode from "arale-qrcode";
export default {
  name: "qrCodeDetails",
  data(){
    return{
      reverse: true,
      activities:[],
      img: "",

    }
  },methods:{
    list(cropNumbering){
      //获取cropNumbering
      //let search = location.search;
      //let string = search.split("=")[1];
      this.axios.post("http://172.20.10.5:8003/api/sys-crop/handleClick?cropNumbering="+cropNumbering).then(res=>{
        this.activities=res.data
      })
    },//生成二维码方法
    makeCode() {
      let search = location.search;
      let string = search.split("=")[1];

      const result = new AraleQRCode({
        render: "svg",      // 定义生成的类型 'svg' or 'table dom’
        text: "http://172.20.10.15:8080/qrcode?cropNumbering="+string, // 二维码的链接
        size: 150,      //二维码大小
      });

      // 将svg xml文档转换成字符串
      const svgXml = new XMLSerializer().serializeToString(result);

      // 将svg字符串转成base64格式，通过 window.btoa方法创建一个 base-64 编码的字符串，进行二次编码解码(encodeURIComponent 字符串进行编码和解码，unescape 进行解码)。
      const src =
          "data:image/svg+xml;base64," +
          window.btoa(unescape(encodeURIComponent(svgXml)));

      // 本地存储图片
//唯一标识
      sessionStorage.setItem("image"+string, src);
      this.getImg();
    },

    // 获取存储的图片给到页面
    getImg() {
      let search = location.search;
      let string = search.split("=")[1];
      this.img = sessionStorage.getItem("image"+string);
      console.log("$$$$", this.img);
      //sessionStorage.removeItem("image"+string);
    },
  },created() {
      //alert(JSON.stringify(this.$route.query.cropNumbering))
      this.list(this.$route.query.cropNumbering);
      //this.makeCode();

  }
}
</script>


<style scoped>

</style>